package com.qixiao.lib.generic.inherit;

public class Test<T> {

    private T one;
    private T two;

    public T getOne() {
        return one;
    }

    public void setOne(T one) {
        this.one = one;
    }

    public T getTwo() {
        return two;
    }

    public void setTwo(T two) {
        this.two = two;
    }

    static class Food {
    }

    static class Apple extends Food {
    }

    private static <T> void set(Test<Food> t) {
    }

    public static void main(String[] args) {
        //Test<Food> 和 Test<Apple> 没有任何关系
        Test<Food> foodTest = new Test<>();
        Test<Apple> appleTest = new Test<>();

        Food food = new Apple();
//        Test<Food> test = new Test<Apple>();//incompatible type 不兼容的类型

        Test<Food> test1 = new ExtendTest<>();
        Test<Apple> test2 = new ExtendTest<>();

        set(foodTest);
//        set(appleTest);//报错
        set(test1);
//        set(test2);//报错

    }

    //泛型类可以继承和扩展其他泛型类 比如List ArrayList
    private static class ExtendTest<T> extends Test<T> {
    }

}
